//活动详情
var activeId = globalFun.GetQueryString('activeId');
Auth()
if(is_team == 1) {
	$("#join_team").css('display', 'none');
} else if(is_team == 2) {
	$("#join_one").css('display', 'none');
}

$.ajax({
	type: "post",
	url: apicom + "/activity/getActivityInfo",
	async: true,
	data: {
		activityId: activeId
	},
	success: function(res) {
		console.log(res)
		if(res.code == 200) {
			var content = res.data;
			$('h3').html(content.title);
			if(content.status == 0) {
				$('.status').html('招募启动')
			} else if(content.status == 1) {
				$('.status').html('招募中')
			} else if(content.status == 2) {
				$('.status').html('已结束')
			} else if(content.status == 3) {
				$('.status').html('延期异常')
			};
			$('.span1').html(content.beginTime + '——' + content.endTime);
			$('.img1').attr('src', content.imgUrl);
			$('.address').html(content.address);
			$('.type').html(content.activityType);
			$('.people').html(content.aimType);
			$('.zm_time').html(content.recruitBegin + '——' + content.recruitEnd);
			$('.fb_time').html(content.createdTime);
			$('.ac_time').html(content.beginTime + '——' + content.endTime);
			$('.sv_time').html(content.serviceTime);
			$('.zm_num').html(content.activityNum);
			$('.ym_num').html(content.nowActivityNum);
			$('.guarantee').html(content.security);
			$('.i_name').html(content.teamName)
			$('.i_address').html('地址:' + content.teamAdress);
			$('.c_people').html(content.memberName);
			$('.c_phone').html('手机:' + content.memberPhone);
			$('.c_mail').html('邮箱:' + content.memberEmail);
			$('#team_d').html(content.description);

		}
	},
	error: function() {

	}
});

//个人报名
$('#join_one').on('click', function() {
	if(localStorage.getItem('user_info')) {
		var joinObj = {
			activityId: activeId,
			uuid: uuid,
			username: name,
			loginId: id,
			loginType: is_team
		}
		$.ajax({
			type: "post",
			url: apicom + "/afterActivity/enlistActivity",
			async: true,
			data: joinObj,
			success: function(res) {
				if(res.code == 200) {
					$('.mengban').css('display', 'block');
					$('.tips').html('报名成功，请等待录用')
				} else if(res.code == 0) {
					$('.mengban').css('display', 'block');
					$('.tips').html(res.message)
				}

			},
			error: function(err) {
				conosle.log(err)
			}
		});

	} else {
		$('.mengban').css('display', 'block');
		$('.tips').html('请先登录在进行报名')
	}

})
//团队报名
$('#join_team').on('click', function() {
	if(localStorage.getItem('user_info')) {
		var joinObj = {
			activityId: activeId,
			uuid: uuid,
			username: name,
			loginId: id,
			loginType: is_team
		}
		$.ajax({
			type: "post",
			url: apicom + "/afterActivity/teamEnlistActivity",
			async: true,
			data: joinObj,
			success: function(res) {
				if(res.code == 200) {
					$('.mengban').css('display', 'block');
					$('.tips').html('报名成功，已向团队成员发送邀请')
				} else if(res.code == 0) {
					$('.mengban').css('display', 'block');
					$('.tips').html(res.message)
				}

			},
			error: function(err) {
				conosle.log(err)
			}
		});

	} else {
		$('.mengban').css('display', 'block');
		$('.tips').html('请先登录在进行报名')
	}
})
//关闭按钮
$('.btn_close').on('click', function() {
	$('.mengban').css('display', 'none');
})
$('.close_s').on('click', function() {
	$('.mengban').css('display', 'none');
})
$('.close_s1').on('click', function() {
	$('.mengban1').css('display', 'none');
})
//切换留言，详情
	$('.team_d').on('click',function(){
		$(this).addClass('t_type');
		$(this).siblings().removeClass('t_type');
		$('#team_d').show();
		$('#c_active').hide();	
		$('.liuyan').hide();	
	})
	$('.c_liuyan').on('click',function(){
		$(this).addClass('t_type');
		$(this).siblings().removeClass('t_type');
		$('#team_d').hide();
		$('#c_active').hide();	
		$('.liuyan').show();	
	})
//渲染评论列表
massge()

function massge() {
	$.ajax({
		type: "post",
		url: apicom + "/activity/commentList",
		async: true,
		data: {
			id: activeId,
			type: 1
		},
		success: function(res) {
			var content = res.data;
			liuyan(content);
		},
		error: function() {

		}
	});
}

function liuyan(pList) {
	var ss = ''
	for(var i = 0; i < pList.length; i++) {
		ss += '<div class="list_one">'
		ss += '<div class="list_top">'
		ss += '<img src="' + pList[i].imgUrl + '"/>'
		ss += '<dl class="hf_dl">'
		ss += '<dt>' + pList[i].name + '</dt>'
		ss += '<dd class="hf_info">' + pList[i].content + '</dd>'
		if(pList[i].commentReplyVOList.length == 0) {
			ss += '<dd class="hf_bottom"><span>' + pList[i].createTime + '</span><span data-name="' + pList[i].name + '" data-id="' + pList[i].id + '" class="huifu">回复</span></dd></dl></div>'
			ss += '</div></div>'
		} else {
			ss += '<dd class="hf_bottom"><span>' + pList[i].createTime + '</span><span data-name="' + pList[i].name + '" data-id="' + pList[i].id + '" class="huifu">回复</span></dd></dl></div><div class="list_bottom">'
			for(var j = 0; j < pList[i].commentReplyVOList.length; j++) {

				ss += '<div class="list_two">'
				ss += '<p class="two_left"><span class="hf_one">' + pList[i].commentReplyVOList[j].name + '</span>回复<span class="hf_two">' + pList[i].commentReplyVOList[j].replyName + '</span>:</p>'
				ss += '<dl class="two_right">'
				ss += '<dt>' + pList[i].commentReplyVOList[j].replyContent + '</dt>'
				ss += '<dd class="hf_bottom1"><span data-name="' + pList[i].commentReplyVOList[j].name + '" data-id="' + pList[i].id + '" class="huifu">回复</span><span>' + pList[i].commentReplyVOList[j].createTime + '</span></dd></dl></div>'

			}
		}

		ss += '</div></div>'

	}
	$('.liuyan_list').html(ss)

}
//发表留言
$('#btn_fb').on('click', function() {
	var liuyan = $('#liuyan').val();
	if(localStorage.getItem('user_info')) {
		var lyObj = {
			commentId: activeId,
			uuid: uuid,
			username: name,
			loginId: id,
			loginType: is_team,
			content: liuyan,
			commentType: 1
		}
		$.ajax({
			type: "post",
			url: apicom + "/comment/addComment",
			async: true,
			data: lyObj,
			success: function(res) {
				if(res.code == 200) {
					$('.mengban').css('display', 'block');
					$('.tips').html('发布成功')
					massge();
				} else if(res.code == 0) {
					$('.mengban').css('display', 'block');
					$('.tips').html(res.message)
				}

			},
			error: function(err) {
				conosle.log(err)
			}
		});

	} else {
		$('.mengban').css('display', 'block');
		$('.tips').html('请先登录后再进行评论')
	}
})
//回复留言
var reaName;
var oneId;//首次回复
$('.message').on('click','.huifu',function() {
	if(localStorage.getItem('user_info')) {
		oneId = $(this).attr('data-id')
		reaName = $(this).attr('data-name')
		$('.mengban1').css('display', 'block');
	} else {
		$('.mengban').css('display', 'block');
		$('.tips').html('请先登录后再进行评论')
	}
})
$('.btn_hf').on('click',function() {
	var liuyan = $('#description').val();
		var hfObj = {
			commentId: oneId,
			uuid: uuid,
			username: name,
			loginId: id,
			loginType: is_team,
			content: liuyan,
			replyName:reaName
		}
		$.ajax({
			type: "post",
			url: apicom + "/comment/replyComment",
			async: true,
			data: hfObj,
			success: function(res) {
				if(res.code == 200) {
					$('.mengban1').css('display', 'none');
					$('.mengban').css('display', 'block');
					$('.tips').html('回复成功')
					massge();
				} else if(res.code == 0) {
					$('.mengban1').css('display', 'block');
					$('.mengban').css('display', 'block');
					$('.tips').html(res.message)
				}

			},
			error: function(err) {
				conosle.log(err)
			}
		});

})
